<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Paraview 脚本一例 | Giskard&#39;s CFD Learning Tricks</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Paraview 提供了一个 python 接口，可以用 python 脚本来控制 Paraview，以实现自动化的后处理。使用方法是，先写一个 python 脚本，里面包含调用 Paraview 的各种语句，然后，用 Paraview 的安装目录的 bin 下的 pvpython 来运行这个脚本即可。本篇用一个例子来说明 python 脚本的写法，以及常用 Paraview 操作对应的语句。">
<meta property="og:type" content="article">
<meta property="og:title" content="Paraview 脚本一例">
<meta property="og:url" content="http://xiaopingqiu.github.io/2016/08/27/ParaviewScritps/index.html">
<meta property="og:site_name" content="Giskard's CFD Learning Tricks">
<meta property="og:description" content="Paraview 提供了一个 python 接口，可以用 python 脚本来控制 Paraview，以实现自动化的后处理。使用方法是，先写一个 python 脚本，里面包含调用 Paraview 的各种语句，然后，用 Paraview 的安装目录的 bin 下的 pvpython 来运行这个脚本即可。本篇用一个例子来说明 python 脚本的写法，以及常用 Paraview 操作对应的语句。">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Paraview 脚本一例">
<meta name="twitter:description" content="Paraview 提供了一个 python 接口，可以用 python 脚本来控制 Paraview，以实现自动化的后处理。使用方法是，先写一个 python 脚本，里面包含调用 Paraview 的各种语句，然后，用 Paraview 的安装目录的 bin 下的 pvpython 来运行这个脚本即可。本篇用一个例子来说明 python 脚本的写法，以及常用 Paraview 操作对应的语句。">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

##ga('create', '[object Object]', 'auto');
ga('create', 'UA-62501686-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Giskard&#39;s CFD Learning Tricks</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">CFD and Scientific Computing</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/atom.xml">Rss</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="q" value="site:http://xiaopingqiu.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-ParaviewScritps" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/08/27/ParaviewScritps/" class="article-date">
  <time datetime="2016-08-27T08:45:24.000Z" itemprop="datePublished">2016-08-27</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Paraview/">Paraview</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Paraview 脚本一例
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Paraview 提供了一个 python 接口，可以用 python 脚本来控制 Paraview，以实现自动化的后处理。使用方法是，先写一个 python 脚本，里面包含调用 Paraview 的各种语句，然后，用 Paraview 的安装目录的 bin 下的 <code>pvpython</code> 来运行这个脚本即可。本篇用一个例子来说明 python 脚本的写法，以及常用 Paraview 操作对应的语句。</p>
<a id="more"></a>
<p>这个脚本实现的功能如下：</p>
<ol>
<li>从指定路径中读取一个 “xxx.foam”</li>
<li>作一个截面，再在截面的基础上作矢量箭头</li>
<li>对截面使用 Surface Vector 这个 filter</li>
<li>对得到的 SurfaceVector 使用 Mask Points</li>
<li>使用 Stream Tracer With Custom Source，其中 Input 为 SurfaceVector，Seed point 为 MaskPoints，这样就得到了 slice 上的流线。</li>
<li>输出流线这个视图的一张屏幕截图</li>
<li>输出流场箭头叠加 slice 这个视图的 11 帧动画，动画输出过程中，Camera 是绕 y 轴旋转的，所以得到的是旋转效果的动画。</li>
</ol>
<p>需要说明的是，以下脚本绝大部分都不是手写的，而是用 trace 功能自动生成的。打开一个空白的 Paraview，选择 Tools-&gt;Satrt Trace，然后，再去进行操作，Paraview 会将你的操作转换成 pvpython 语句，完成以后再 Tools-&gt;Stop Strace，就自动生成了一个脚本。</p>
<p>下面先给出脚本的全部，然后在脚本中给出注释，最后再给出一些额外的说明。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span>: paraview.simple</span><br><span class="line"><span class="keyword">except</span>: <span class="keyword">from</span> paraview.simple <span class="keyword">import</span> *  <span class="comment">## 这是 python 的语法，注意 pvpython 是基于 python 的，使用的完全是 python 的语法</span></span><br><span class="line">paraview.simple._DisableFirstRenderCameraReset()</span><br><span class="line"></span><br><span class="line">pM_foam = OpenFOAMReader( FileName=<span class="string">'E:\\OF_tutorials\\mapped\\pitzDailyMapped\\pM.foam'</span> )  <span class="comment">## 用 OpenFOAMReader 读取一个 "xxx.foam" 文件</span></span><br><span class="line"></span><br><span class="line">AnimationScene1 = GetAnimationScene()  <span class="comment">## 获取动画操作的接口</span></span><br><span class="line">AnimationScene1.EndTime = <span class="number">0.1</span></span><br><span class="line">AnimationScene1.PlayMode = <span class="string">'Snap To TimeSteps'</span> </span><br><span class="line"></span><br><span class="line">pM_foam.CellArrays = [<span class="string">'U'</span>, <span class="string">'UMean'</span>, <span class="string">'UPrime2Mean'</span>, <span class="string">'U_0'</span>, <span class="string">'k'</span>, <span class="string">'k_0'</span>, <span class="string">'nuSgs'</span>, <span class="string">'nuTilda'</span>, <span class="string">'p'</span>, <span class="string">'pMean'</span>, <span class="string">'pPrime2Mean'</span>]  <span class="comment">## 获取可显示的场数据</span></span><br><span class="line">pM_foam.MeshRegions = [<span class="string">'internalMesh'</span>]</span><br><span class="line"></span><br><span class="line">RenderView1 = GetRenderView()  <span class="comment">## 获取当前窗口的接口</span></span><br><span class="line">RenderView1.CenterOfRotation = [<span class="number">0.10999999567866325</span>, <span class="number">0.0</span>, <span class="number">0.0</span>] </span><br><span class="line"></span><br><span class="line">RenderView1.Background = (<span class="number">81.0</span>/<span class="number">255.0</span>, <span class="number">87.0</span>/<span class="number">255.0</span>, <span class="number">110.0</span>/<span class="number">255.0</span>)  <span class="comment">## 设置窗口的背景色，注意这里使用的RGB值是用 255 归一化的，即颜色值范围是 0~1</span></span><br><span class="line">RenderView1.ViewSize = [<span class="number">1086</span>,<span class="number">642</span>]   <span class="comment">## 设置窗口的大小</span></span><br><span class="line">RenderView1.CameraViewAngle = <span class="number">30</span>    <span class="comment">## 设置相机的远近，这个值越大，相机越远</span></span><br><span class="line">RenderView1.CenterAxesVisibility=<span class="number">0</span>  <span class="comment">## 设置窗口旋转中心十字的显示，0 为不显示，1为显示</span></span><br><span class="line"></span><br><span class="line">DataRepresentation1 = Show()        <span class="comment">## 获取当前 source 的操作接口 </span></span><br><span class="line"><span class="comment">#DataRepresentation1.ConstantRadius = 0.28999999165534973</span></span><br><span class="line">DataRepresentation1.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation1.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation1.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation1.SelectionCellFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation1.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'p'</span>)</span><br><span class="line">DataRepresentation1.ScalarOpacityUnitDistance = <span class="number">0.015162935987203615</span></span><br><span class="line">DataRepresentation1.Texture = []</span><br><span class="line">DataRepresentation1.ExtractedBlockIndex = <span class="number">1</span></span><br><span class="line"><span class="comment">#DataRepresentation1.RadiusRange = [-0.07000000029802322, 0.28999999165534973]</span></span><br><span class="line">DataRepresentation1.ScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line"></span><br><span class="line">a1_p_PVLookupTable = GetLookupTableForArray( <span class="string">"p"</span>, <span class="number">1</span>, RGBPoints=[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">1e-16</span>, <span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>], VectorMode=<span class="string">'Magnitude'</span>, NanColor=[<span class="number">0.498039</span>, <span class="number">0.498039</span>, <span class="number">0.498039</span>], ColorSpace=<span class="string">'HSV'</span>, ScalarRangeInitialized=<span class="number">1.0</span> )</span><br><span class="line"></span><br><span class="line">a1_p_PiecewiseFunction = CreatePiecewiseFunction( Points=[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>, <span class="number">1e-16</span>, <span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>] )</span><br><span class="line"></span><br><span class="line">DataRepresentation1.ScalarOpacityFunction = a1_p_PiecewiseFunction</span><br><span class="line">DataRepresentation1.LookupTable = a1_p_PVLookupTable</span><br><span class="line"><span class="comment">#DataRepresentation1.RadiusRange = [-0.07, 0.29]</span></span><br><span class="line"></span><br><span class="line">a1_p_PVLookupTable.ScalarOpacityFunction = a1_p_PiecewiseFunction</span><br><span class="line"></span><br><span class="line">RenderView1.CameraPosition = [<span class="number">0.10999999567866325</span>, <span class="number">0.0</span>, <span class="number">0.7023592915690968</span>]</span><br><span class="line">RenderView1.CameraFocalPoint = [<span class="number">0.10999999567866325</span>, <span class="number">0.0</span>, <span class="number">0.0</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6943406986061459</span>, <span class="number">0.7141471810021238</span>]</span><br><span class="line">RenderView1.CameraParallelScale = <span class="number">0.18178396116279658</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">######### generate a slice ################</span></span><br><span class="line">Slice1 = Slice( SliceType=<span class="string">"Plane"</span> )    <span class="comment">## 作一个截面</span></span><br><span class="line"></span><br><span class="line">Slice1.SliceOffsetValues = [<span class="number">0.0</span>]  <span class="comment">## 截面属性的设置，想必这种不需要解释，因为属性名字跟Paraview里是一样的</span></span><br><span class="line">Slice1.SliceType.Origin = [<span class="number">0.11</span>, <span class="number">0.0</span>, <span class="number">0.0</span>]</span><br><span class="line">Slice1.SliceType = <span class="string">"Plane"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># toggle the 3D widget visibility.</span></span><br><span class="line"><span class="comment">#active_objects.source.SMProxy.InvokeEvent('UserEvent', 'ShowWidget')</span></span><br><span class="line"><span class="comment">#RenderView1.CameraClippingRange = [0.4287074803602159, 1.0485246743217493]</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># toggle the 3D widget visibility.</span></span><br><span class="line">active_objects.source.SMProxy.InvokeEvent(<span class="string">'UserEvent'</span>, <span class="string">'HideWidget'</span>)    <span class="comment">## 这句在后面有说明</span></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6943406986061459</span>, <span class="number">0.7141471810021238</span>]</span><br><span class="line"></span><br><span class="line">Slice1.SliceType.Normal = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation2 = Show()</span><br><span class="line"><span class="comment">#DataRepresentation2.ConstantRadius = 0.28999999165534973</span></span><br><span class="line">DataRepresentation2.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation2.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation2.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation2.SelectionCellFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation2.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'p'</span>)</span><br><span class="line">DataRepresentation2.Texture = []</span><br><span class="line">DataRepresentation2.LookupTable = a1_p_PVLookupTable</span><br><span class="line"><span class="comment">#DataRepresentation2.RadiusRange = [-0.07000000029802322, 0.28999999165534973]</span></span><br><span class="line">DataRepresentation2.ScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line"></span><br><span class="line">DataRepresentation1.Visibility = <span class="number">0</span>  <span class="comment">## 把第一个source设置为不显示，对应着在 Paraview 里，将pipeline中 PM.foam 前面的“眼睛” 关掉</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6953356986534058</span>, <span class="number">0.7128946809426333</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation2.RadiusRange = [-0.07, 0.29]</span></span><br><span class="line">DataRepresentation2.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'U'</span>)  <span class="comment">## 将颜色显示改为用速度来显示。</span></span><br><span class="line"></span><br><span class="line">a3_U_PVLookupTable = GetLookupTableForArray( <span class="string">"U"</span>, <span class="number">3</span>, RGBPoints=[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">16.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>], VectorMode=<span class="string">'Magnitude'</span>, NanColor=[<span class="number">0.498039</span>, <span class="number">0.498039</span>, <span class="number">0.498039</span>], ColorSpace=<span class="string">'HSV'</span>, ScalarRangeInitialized=<span class="number">1.0</span>, LockScalarRange=<span class="number">1</span> )   <span class="comment">## 这里是设置速度的范围，以及速度与颜色的映射关系</span></span><br><span class="line"></span><br><span class="line">a3_U_PiecewiseFunction = CreatePiecewiseFunction( Points=[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>, <span class="number">16.0</span>, <span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>] )</span><br><span class="line"></span><br><span class="line">AnimationScene1.AnimationTime = <span class="number">0.1</span></span><br><span class="line"></span><br><span class="line">ScalarBarWidgetRepresentation1 = CreateScalarBar( ComponentTitle=<span class="string">'Magnitude'</span>, Title=<span class="string">'U'</span>, Enabled=<span class="number">1</span>, LabelFontSize=<span class="number">12</span>, LookupTable=a3_U_PVLookupTable, TitleFontSize=<span class="number">12</span> )</span><br><span class="line">GetRenderView().Representations.append(ScalarBarWidgetRepresentation1)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">###### generate a glyph #################</span></span><br><span class="line">Glyph1 = Glyph( GlyphType=<span class="string">"Arrow"</span>, GlyphTransform=<span class="string">"Transform2"</span> )   <span class="comment">## 作流场箭头</span></span><br><span class="line"></span><br><span class="line">DataRepresentation2.LookupTable = a3_U_PVLookupTable</span><br><span class="line"></span><br><span class="line">a3_U_PVLookupTable.ScalarOpacityFunction = a3_U_PiecewiseFunction</span><br><span class="line"></span><br><span class="line">Glyph1.Scalars = [<span class="string">'POINTS'</span>, <span class="string">'p'</span>]</span><br><span class="line">Glyph1.SetScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line">Glyph1.Vectors = [<span class="string">'POINTS'</span>, <span class="string">'U'</span>]</span><br><span class="line">Glyph1.GlyphTransform = <span class="string">"Transform2"</span></span><br><span class="line">Glyph1.GlyphType = <span class="string">"Arrow"</span></span><br><span class="line"></span><br><span class="line">Glyph1.SetScaleFactor = <span class="number">0.01</span></span><br><span class="line">Glyph1.ScaleMode = <span class="string">'off'</span></span><br><span class="line">Glyph1.MaximumNumberofPoints = <span class="number">1000</span></span><br><span class="line"></span><br><span class="line">DataRepresentation3 = Show()</span><br><span class="line"><span class="comment">#DataRepresentation3.ConstantRadius = 0.2999996840953827</span></span><br><span class="line">DataRepresentation3.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation3.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation3.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation3.SelectionCellFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation3.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'U'</span>)</span><br><span class="line">DataRepresentation3.Texture = []</span><br><span class="line"><span class="comment">#DataRepresentation3.RadiusRange = [-0.07000353187322617, 0.2999996840953827]</span></span><br><span class="line">DataRepresentation3.ScaleFactor = <span class="number">0.03700032159686089</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation3.ColorArrayName = ('POINT_DATA', '')</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6936123081169067</span>, <span class="number">0.7150640745576737</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation3.RadiusRange = [-0.0700035, 0.3]</span></span><br><span class="line">DataRepresentation3.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'p'</span>)</span><br><span class="line">DataRepresentation3.LookupTable = a1_p_PVLookupTable</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Texture = []</span><br><span class="line">DataRepresentation2.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">ScalarBarWidgetRepresentation1.Enabled = <span class="number">0</span></span><br><span class="line">ScalarBarWidgetRepresentation1.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">a1_p_PVLookupTable.RGBPoints = [-<span class="number">96.12127685546875</span>, <span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">61.768226623535156</span>, <span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>]</span><br><span class="line"></span><br><span class="line">a1_p_PiecewiseFunction.Points = [-<span class="number">96.12127685546875</span>, <span class="number">0.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>, <span class="number">61.768226623535156</span>, <span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">###### generate a surface vector ###################</span></span><br><span class="line">SetActiveSource(Slice1)  <span class="comment">## 将截面这个 source 设置为当前的source ，即对应在 Paraview 里用鼠标选择 slice</span></span><br><span class="line">SurfaceVectors1 = SurfaceVectors()   <span class="comment">## 然后，在 slice 上使用 Surface Vectors 这个 fliter</span></span><br><span class="line"></span><br><span class="line">SurfaceVectors1.SelectInputVectors = [<span class="string">'POINTS'</span>, <span class="string">'U'</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation4 = Show()</span><br><span class="line"><span class="comment">#DataRepresentation4.ConstantRadius = 0.28999999165534973</span></span><br><span class="line">DataRepresentation4.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation4.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation4.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation4.SelectionCellFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation4.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'U'</span>)</span><br><span class="line">DataRepresentation4.Texture = []</span><br><span class="line">DataRepresentation4.LookupTable = a3_U_PVLookupTable</span><br><span class="line"><span class="comment">#DataRepresentation4.RadiusRange = [-0.07000000029802322, 0.28999999165534973]</span></span><br><span class="line">DataRepresentation4.ScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation4.RadiusRange = [-0.07, 0.29]</span></span><br><span class="line"></span><br><span class="line">DataRepresentation3.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6953356986534058</span>, <span class="number">0.7128946809426333</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.002996152353161611</span>, <span class="number">2.9961523531616105</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation4.Visibility = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">ScalarBarWidgetRepresentation1.Enabled = <span class="number">1</span></span><br><span class="line">ScalarBarWidgetRepresentation1.Visibility = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraPosition = [<span class="number">0.10999999567866325</span>, <span class="number">0.0</span>, <span class="number">0.702356634767752</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.6953330684200745</span>, <span class="number">0.7128919842892683</span>]</span><br><span class="line">RenderView1.CameraParallelScale = <span class="number">0.1817832735320095</span></span><br><span class="line"></span><br><span class="line">DataRepresentation4.Texture = []</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#####  generate a maskpoint ##########################</span></span><br><span class="line">MaskPoints1 = MaskPoints()  <span class="comment">## 在 SurfaceVector1 的基础上使用 Mask Points 这个filter</span></span><br><span class="line"></span><br><span class="line">MaskPoints1.GenerateVertices = <span class="number">1</span></span><br><span class="line">MaskPoints1.RandomSampling = <span class="number">1</span></span><br><span class="line">MaskPoints1.RandomSamplingMode = <span class="string">'Spatially Stratified Random Sampling'</span></span><br><span class="line">MaskPoints1.MaximumNumberofPoints = <span class="number">1000</span></span><br><span class="line"></span><br><span class="line">DataRepresentation5 = Show()</span><br><span class="line"><span class="comment">#DataRepresentation5.ConstantRadius = 0.28999999165534973</span></span><br><span class="line">DataRepresentation5.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation5.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation5.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation5.SelectionCellFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation5.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'U'</span>)</span><br><span class="line">DataRepresentation5.Texture = []</span><br><span class="line">DataRepresentation5.LookupTable = a3_U_PVLookupTable</span><br><span class="line"><span class="comment">#DataRepresentation5.RadiusRange = [-0.07000000029802322, 0.28999999165534973]</span></span><br><span class="line">DataRepresentation5.ScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line"></span><br><span class="line">DataRepresentation4.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation5.RadiusRange = [-0.07, 0.29]</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">####### generate stream line on a surface #########################</span></span><br><span class="line">SetActiveSource(SurfaceVectors1)  <span class="comment">## 选定 SurfaceVectors1，在此基础上，使用 Stream Tracer With Custom Source 这个 fliter。因此，这种情况下，Input 就等于 SurfaceVectors1 了</span></span><br><span class="line">StreamTracerWithCustomSource1 = StreamTracerWithCustomSource( SeedSource=MaskPoints1 ) <span class="comment">## 本来这里括号里应该还需要指定 Input 的，但是上一句已经默认了 Input 为 SurfaceVectors1</span></span><br><span class="line"></span><br><span class="line">StreamTracerWithCustomSource1.Vectors = [<span class="string">'POINTS'</span>, <span class="string">'U'</span>]</span><br><span class="line">StreamTracerWithCustomSource1.MaximumStreamlineLength = <span class="number">0.35999999195337296</span></span><br><span class="line"></span><br><span class="line">StreamTracerWithCustomSource1.MaximumError = <span class="number">1e-06</span></span><br><span class="line">StreamTracerWithCustomSource1.TerminalSpeed = <span class="number">1e-12</span></span><br><span class="line"></span><br><span class="line">DataRepresentation6 = Show()</span><br><span class="line"><span class="comment">#DataRepresentation6.ConstantRadius = 0.28999999165534973</span></span><br><span class="line">DataRepresentation6.EdgeColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5000076295109483</span>]</span><br><span class="line"><span class="comment">#DataRepresentation6.PointSpriteDefaultsInitialized = 1</span></span><br><span class="line">DataRepresentation6.SelectionPointFieldDataArrayName = <span class="string">'p'</span></span><br><span class="line">DataRepresentation6.SelectionCellFieldDataArrayName = <span class="string">'ReasonForTermination'</span></span><br><span class="line">DataRepresentation6.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">'U'</span>)</span><br><span class="line">DataRepresentation6.Texture = []</span><br><span class="line">DataRepresentation6.LookupTable = a3_U_PVLookupTable</span><br><span class="line"><span class="comment">#DataRepresentation6.RadiusRange = [-0.07000000029802322, 0.28999999165534973]</span></span><br><span class="line">DataRepresentation6.ScaleFactor = <span class="number">0.0359999991953373</span></span><br><span class="line"></span><br><span class="line">DataRepresentation5.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#DataRepresentation6.RadiusRange = [-0.07, 0.29]</span></span><br><span class="line">DataRepresentation6.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">''</span>)</span><br><span class="line"></span><br><span class="line">ScalarBarWidgetRepresentation1.Enabled = <span class="number">0</span></span><br><span class="line">ScalarBarWidgetRepresentation1.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">MaskPoints1.MaximumNumberofPoints = <span class="number">200</span></span><br><span class="line"></span><br><span class="line">DataRepresentation6.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation6.Opacity = <span class="number">0.7</span></span><br><span class="line">DataRepresentation6.DiffuseColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation4.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation4.Visibility = <span class="number">1</span>  <span class="comment">## 开启 SurfaceVectors1 的显示</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraPosition = [<span class="number">0.10999999567866325</span>, <span class="number">0.0</span>, <span class="number">0.4797190320113051</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.47492184169119206</span>, <span class="number">0.4869148174914747</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">DataRepresentation4.Texture = []</span><br><span class="line"></span><br><span class="line">WriteImage(<span class="string">'E:/OF_tutorials/mapped/pitzDailyMapped/testscreen.png'</span>, Magnification=<span class="number">2</span>)  <span class="comment">## 将 SurfaceVectors1 和 stream line 叠加的视图输出为屏幕截图，截图大小为设置的窗口大小的两倍</span></span><br><span class="line"></span><br><span class="line">DataRepresentation6.Visibility = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">DataRepresentation4.Visibility = <span class="number">0</span> <span class="comment">## 关闭 SurfaceVectors1 的显示</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.0026043054963398975</span>, <span class="number">2.6043054963398973</span>]</span><br><span class="line"></span><br><span class="line">DataRepresentation3.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation3.Visibility = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">RenderView1.CameraPosition = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.725254404116244</span>]</span><br><span class="line">RenderView1.CameraFocalPoint = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.7162784695385823</span>, <span class="number">0.7383026137930281</span>]</span><br><span class="line">RenderView1.CenterOfRotation = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>]</span><br><span class="line">RenderView1.CameraParallelScale = <span class="number">0.18770965232976394</span></span><br><span class="line"></span><br><span class="line">DataRepresentation2.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation2.Visibility = <span class="number">1</span>  <span class="comment">## 开启 slice 的显示 </span></span><br><span class="line"></span><br><span class="line">DataRepresentation3.Texture = []</span><br><span class="line"></span><br><span class="line">DataRepresentation3.ColorArrayName = (<span class="string">'POINT_DATA'</span>, <span class="string">''</span>)</span><br><span class="line">DataRepresentation3.DiffuseColor = [<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>]</span><br><span class="line"></span><br><span class="line">RenderView1.CameraPosition = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.599383805054747</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.5916665764677003</span>, <span class="number">0.6105439557456087</span>]</span><br><span class="line"></span><br><span class="line">AnimationScene1.AnimationTime = <span class="number">0.0</span></span><br><span class="line">AnimationScene1.PlayMode = <span class="string">'Sequence'</span>   <span class="comment">## 设置动画的播放模式</span></span><br><span class="line">AnimationScene1.NumberOfFrames = <span class="number">11</span></span><br><span class="line"></span><br><span class="line">CameraAnimationCue1 = GetCameraTrack()</span><br><span class="line">CameraAnimationCue1.AnimatedProxy = RenderView1</span><br><span class="line">CameraAnimationCue1.Mode = <span class="string">'Path-based'</span> <span class="comment">## 设置 Camera 的旋转</span></span><br><span class="line"></span><br><span class="line">TimeAnimationCue1 = GetTimeTrack()</span><br><span class="line"></span><br><span class="line">KeyFrame5047 = CameraKeyFrame( FocalPathPoints=[<span class="number">0.114998</span>, <span class="number">0.000388026</span>, <span class="number">0.0</span>], FocalPoint=[<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>], PositionPathPoints=[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5</span>, <span class="number">0.43120039439853625</span>, <span class="number">0.0</span>, <span class="number">0.40403042680054746</span>, <span class="number">0.6279812289875636</span>, <span class="number">0.0</span>, <span class="number">0.008529172380306538</span>, <span class="number">0.4444572181383874</span>, <span class="number">0.0</span>, -<span class="number">0.39329526260513553</span>, <span class="number">0.016685579000083814</span>, <span class="number">0.0</span>, -<span class="number">0.5035466293017314</span>, -<span class="number">0.3382012405958345</span>, <span class="number">0.0</span>, -<span class="number">0.24048906072285084</span>, -<span class="number">0.35710462563060374</span>, <span class="number">0.0</span>, <span class="number">0.20085728982710624</span>], ClosedPositionPath=<span class="number">1</span>, ParallelScale=<span class="number">0.18770965232976394</span>, Position=[<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.725254404116244</span>] )</span><br><span class="line"></span><br><span class="line">KeyFrame5048 = CameraKeyFrame( ParallelScale=<span class="number">0.18770965232976394</span>, Position=[<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.725254404116244</span>], KeyTime=<span class="number">1.0</span>, FocalPoint=[<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>] )</span><br><span class="line"></span><br><span class="line">CameraAnimationCue1.KeyFrames = [ KeyFrame5047, KeyFrame5048 ]</span><br><span class="line"></span><br><span class="line">RenderView1.CameraFocalPoint = [<span class="number">0.10459624231466369</span>, <span class="number">0.000388026</span>, -<span class="number">0.002392362660596616</span>]</span><br><span class="line">RenderView1.CameraClippingRange = [<span class="number">0.5303500129360129</span>, <span class="number">0.7361458699228238</span>]</span><br><span class="line">RenderView1.CameraPosition = [-<span class="number">0.03455133768533633</span>, -<span class="number">8.148545999999996e-05</span>, <span class="number">0.6026076373394033</span>]</span><br><span class="line"></span><br><span class="line">WriteAnimation(<span class="string">'E:/OF_tutorials/mapped/pitzDailyMapped/ani/rotateTest.png'</span>, Magnification=<span class="number">2</span>, Quality=<span class="number">2</span>, FrameRate=<span class="number">15.000000</span>)  <span class="comment">## 输出动画，</span></span><br><span class="line"></span><br><span class="line">Render()</span><br></pre></td></tr></table></figure>
<h5 id="一些细节：">一些细节：</h5><ul>
<li><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">active_objects<span class="class">.source</span><span class="class">.SMProxy</span><span class="class">.InvokeEvent</span>(<span class="string">'UserEvent'</span>, <span class="string">'HideWidget'</span>)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>语句的作用是，不显示 slice 的时候产生的哪个边框，即相当于 Paraview 里点掉 slice 的 “Show Plane”。</p>
<ul>
<li><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">RenderView1<span class="class">.Background</span> = (<span class="number">81.0</span>/<span class="number">255.0</span>, <span class="number">87.0</span>/<span class="number">255.0</span>, <span class="number">110.0</span>/<span class="number">255.0</span>)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>作用是设置 RenderView1 的背景颜色。如果是直接在 Paraview 里以宏的形式运行脚本，那不需要这个，但若是用 pvpython 来运行脚本则需要，否则背景是黑色的。另外，这里的 RGB 颜色是用 255 归一化过的。</p>
<ul>
<li>颜色显示应该是以下几个语句的结果<figure class="highlight nix"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">a3_U_PVLookupTable =</span> GetLookupTableForArray( <span class="string">"U"</span>, <span class="number">3</span>, <span class="variable">RGBPoints=</span>[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>, <span class="number">16.0</span>, <span class="number">1.0</span>, <span class="number">0.0</span>, <span class="number">0.0</span>], <span class="variable">VectorMode=</span>'Magnitude', <span class="variable">NanColor=</span>[<span class="number">0.498039</span>, <span class="number">0.498039</span>, <span class="number">0.498039</span>], <span class="variable">ColorSpace=</span>'HSV', <span class="variable">ScalarRangeInitialized=</span><span class="number">1.0</span>, <span class="variable">LockScalarRange=</span><span class="number">1</span> )</span><br><span class="line"></span><br><span class="line"><span class="variable">a3_U_PiecewiseFunction =</span> CreatePiecewiseFunction( <span class="variable">Points=</span>[<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>, <span class="number">16.0</span>, <span class="number">1.0</span>, <span class="number">0.5</span>, <span class="number">0.0</span>] )</span><br><span class="line"></span><br><span class="line">DataRepresentation4.<span class="variable">LookupTable =</span> a3_U_PVLookupTable</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>至于 LookupTable 中，RGBPoints 的构建规则，细节不清楚。这种套用模板就好了，没必要自己手动写。</p>
<ul>
<li>相机的位置，即在 Paraview 里看到的图片的位置，旋转角度，远近等，由以下语句控制：<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">RenderView1<span class="class">.CameraPosition</span> = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.725254404116244</span>]</span><br><span class="line">RenderView1<span class="class">.CameraFocalPoint</span> = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>]</span><br><span class="line">RenderView1<span class="class">.CameraClippingRange</span> = [<span class="number">0.7162784695385823</span>, <span class="number">0.7383026137930281</span>]</span><br><span class="line">RenderView1<span class="class">.CenterOfRotation</span> = [<span class="number">0.11499807611107826</span>, <span class="number">0.00038802623748779297</span>, <span class="number">0.0</span>]</span><br><span class="line">RenderView1<span class="class">.CameraParallelScale</span> = <span class="number">0.18770965232976394</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>这些数据对不同算例是不一样的，需要根据特定情景来修改。没必要手动改，应该用 trace 功能来生成这些坐标值。</p>
<ul>
<li>关于相机选择部分，参考之前<a href="http://xiaopingqiu.github.io/2016/08/27/ParaviewCamera/" target="_blank" rel="external">那篇</a>讲添加旋转相机的。这些代码也应该用 trace 来生成，一般情况下没必要自找麻烦去手写。</li>
</ul>
<p>最后附上一些上面脚本中没有涉及到，但可能会用到的功能：</p>
<ol>
<li>dir 用来查找一个对象所有可调用的函数，比如，假如 slice1 是一个 Slice 的对象，dir(slice1)，则将列出所有 slice1 可以调用的函数或者成员。help(slice1) 类似，而且会列出每个函数的简短说明，这是 python 的特性。</li>
<li><p>关于动画时间的操作</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">animationScene1.GoToNext() <span class="preprocessor">## 下一帧 </span></span><br><span class="line"></span><br><span class="line">animationScene1.Play()  <span class="preprocessor">## 播放动画</span></span><br><span class="line"></span><br><span class="line">animationScene1.GoToFirst()  <span class="preprocessor">## 跳到开始</span></span><br><span class="line"></span><br><span class="line">animationScene1.GoToLast()  <span class="preprocessor">## 跳到最后</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>Hide, Show, Render<br>Hide 和 Show 可以作用于 pipeline 里的每个条目，使其隐藏/可见，对应 paraview 关闭/点亮某个“眼睛”。Render 是当改变了某个显示属性后，要想显示出改变以后的效果需要调用的函数，相当于 Paraview 里点 Apply。</p>
</li>
<li>setActiveSource，getActiveSource，setActiveView，getActiveView<br>这四个，作用分别是，将某个 pipeline设为选定状态，相当于鼠标选中某个 pipeline；获取当前选定的 pipeline；将某个 窗口设为选定状态（针对有多个窗口的情形）；返回当前选定的窗口。此外，还有很多对 pipeline 和 窗口进行操作的接口，需要时查即可。</li>
<li><p>pvpython 本质上就是 python，所以，python 的语法都可以用。比如，下面是一个循环删除所有 pipeline 的方法</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> key <span class="keyword">in</span> <span class="function"><span class="title">GetSources</span><span class="params">()</span></span>.<span class="function"><span class="title">keys</span><span class="params">()</span></span>:</span><br><span class="line">     s = <span class="function"><span class="title">GetSources</span><span class="params">()</span></span>[key]</span><br><span class="line">     <span class="function"><span class="title">Delete</span><span class="params">(s)</span></span></span><br><span class="line">     <span class="tag">del</span> s</span><br></pre></td></tr></table></figure>
</li>
<li><p>Paraview 的 python shell（Tools-&gt;Python Shell），可以当作是一个 pvpython 的 IDE，里面可以方便地进行命令补全，并且每条语句的效果可以即时地显示在 Paraview 中，调试脚本的时候非常有用。</p>
<p>最后说明一下，上述脚本只适用于 Paraview-4.1，在 Paraview-5.0 以后，接口的名字有所变化，这里给出一个<a href="https://github.com/xiaopingqiu/ParaviewScripts" target="_blank" rel="external">链接</a>，感兴趣的读者可以在链接中找到本文中介绍的脚本以及另一个适用于 Paraview-5.0 的脚本。</p>
</li>
</ol>
<p>参考：</p>
<ol>
<li><a href="http://www.paraview.org/Wiki/ParaView/Python_Scripting" target="_blank" rel="external">http://www.paraview.org/Wiki/ParaView/Python_Scripting</a></li>
<li><a href="http://www.paraview.org/Wiki/Python_recipes" target="_blank" rel="external">http://www.paraview.org/Wiki/Python_recipes</a></li>
<li><a href="http://www.paraview.org/ParaView/Doc/Nightly/www/py-doc/index.html" target="_blank" rel="external">http://www.paraview.org/ParaView/Doc/Nightly/www/py-doc/index.html</a></li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xiaopingqiu.github.io/2016/08/27/ParaviewScritps/" data-id="cj2lay3680057kkmb9qv3x1nx" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Postprocessing/">Postprocessing</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/05/12/duoshuoAnnouncement/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          多说评论系统将停止提供服务
        
      </div>
    </a>
  
  
    <a href="/2016/08/27/ParaviewCamera/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Paraview 中有关 Camera 的操作两例</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <!-- 多说评论框 start -->
  <div class="ds-thread" data-thread-key="post-ParaviewScritps" data-title="Paraview 脚本一例" data-url="http://xiaopingqiu.github.io/2016/08/27/ParaviewScritps/"></div>
  <!-- 多说评论框 end -->
  <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
  <script type="text/javascript">
  var duoshuoQuery = {short_name:"xiaopingqiu"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
  <!-- 多说公共JS代码 end -->
</section>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C++</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DEM/">DEM</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/OpenFOAM/">OpenFOAM</a><span class="category-list-count">44</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Paraview/">Paraview</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/swak4Foam/">swak4Foam</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/test/">test</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/vim/">vim</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Boundary-conditions/">Boundary conditions</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C++</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CentOS/">CentOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Code-Explained/">Code Explained</a><span class="tag-list-count">29</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LES/">LES</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LIGGGHTS/">LIGGGHTS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ODE/">ODE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a><span class="tag-list-count">20</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Postprocessing/">Postprocessing</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preprocessing/">Preprocessing</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RTS/">RTS</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TIL/">TIL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Windows/">Windows</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fvOptions/">fvOptions</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovyBC/">groovyBC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/paraview/">paraview</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/turbulence-model/">turbulence model</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wall-functions/">wall functions</a><span class="tag-list-count">4</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Boundary-conditions/" style="font-size: 15.56px;">Boundary conditions</a><a href="/tags/C/" style="font-size: 11.11px;">C++</a><a href="/tags/CentOS/" style="font-size: 10px;">CentOS</a><a href="/tags/Code-Explained/" style="font-size: 20px;">Code Explained</a><a href="/tags/LES/" style="font-size: 10px;">LES</a><a href="/tags/LIGGGHTS/" style="font-size: 10px;">LIGGGHTS</a><a href="/tags/ODE/" style="font-size: 10px;">ODE</a><a href="/tags/OpenFOAM/" style="font-size: 18.89px;">OpenFOAM</a><a href="/tags/Postprocessing/" style="font-size: 17.78px;">Postprocessing</a><a href="/tags/Preprocessing/" style="font-size: 11.11px;">Preprocessing</a><a href="/tags/RTS/" style="font-size: 12.22px;">RTS</a><a href="/tags/TIL/" style="font-size: 10px;">TIL</a><a href="/tags/Windows/" style="font-size: 10px;">Windows</a><a href="/tags/fvOptions/" style="font-size: 11.11px;">fvOptions</a><a href="/tags/groovyBC/" style="font-size: 10px;">groovyBC</a><a href="/tags/paraview/" style="font-size: 10px;">paraview</a><a href="/tags/test/" style="font-size: 11.11px;">test</a><a href="/tags/thermophysicalModels/" style="font-size: 14.44px;">thermophysicalModels</a><a href="/tags/turbulence-model/" style="font-size: 16.67px;">turbulence model</a><a href="/tags/vim/" style="font-size: 10px;">vim</a><a href="/tags/wall-functions/" style="font-size: 13.33px;">wall functions</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">八月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">六月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">五月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">四月 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/05/12/duoshuoAnnouncement/">多说评论系统将停止提供服务</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewScritps/">Paraview 脚本一例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCamera/">Paraview 中有关 Camera 的操作两例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCustomFilter/">Paraview 中创建 Custom Filter</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewStreamLineOnSlice/">在 Paraview 中画截面上的流线</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Giskard Q.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

<script src="//dn-lbstatics.qbox.me/lbservice/busuanzi/2.0/busuanzi.mini.js"/></script>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/atom.xml" class="mobile-nav-link">Rss</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-62501686-1', 'auto');
  ga('send', 'pageview');

</script>

  </div>
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</body>
</html>